/**
 * 
 */
package util;

import java.io.IOException;


import core.KrnResponse;
import listener.OnGetListener;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author Crystalline
 * @GiteePage https://gitee.com/crystallineDW/krn
 */
public class GetUtil {

	public KrnResponse Get_MainThread(final OkHttpClient HttpClient,final String url) throws IOException {


            try{
                final Request request = new Request.Builder()
                        .url(url)
                        .build();
                final Call call = HttpClient.newCall(request);

                Response response = call.execute();
                return new KrnResponse(response);
            }catch (Exception e){
                return new KrnResponse(e);
            }




	}
	
	public void Get_ChildThread(final OkHttpClient HttpClient,final String url,final OnGetListener listener) {


		Request request = new Request.Builder()
                .url(url)
                .build();

        HttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onGet_Failed(e);
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                listener.onGet_Success(new KrnResponse(response));

            }
        });
        
	}
	
}
